<admintpl file="header" />
<style>
	*{ margin:0px; padding:0px;}
	body {
	  margin: 0 auto;
	  background:#fff;
	  font-family:"微软雅黑";
	  font-size:12px;
	}
	ul, li{
		margin: 0px;
		padding: 0px;
		list-style: none;
	}
	a img{border:0;}
	.clear{ clear:both;}
	table.table_wrap{width:100%;}
	table.table_wrap td.tdw{width:75%;}
	
	table.table_wrap td.tdw .title{background:#dde4e6; color:#2c3e50; font-size:20px; font-weight:bold; text-align:center; height:50px; line-height:50px; margin-right:3.33%; position:relative;}
	table.table_wrap td.tdw .title .add_btn{position:absolute; height:30px; text-decoration:none; font-size:12px; border-radius:3px; line-height:30px; right:20px; display:block; top:10px; padding:0 10px; background:#2c3e50; color:#fff;}
	table.table_wrap td.tdw ul.db_lists{zoom:1; overflow:hidden; padding:20px 0 0 0;}
	table.table_wrap td.tdw ul.db_lists li{width:30%; float:left; display:inline; background:#fff; margin-right:3.33%; margin-bottom:20px;}
	table.table_wrap td.tdw ul.db_lists li .d_title{border:1px solid #ddd; background:#ecf0f1; text-align:center; height:40px; line-height:40px; font-size:16px; color:#2c3e50; font-weight:bold;}
	table.table_wrap td.tdw ul.db_lists li .con{border-left:1px solid #ddd; border-right:1px solid #ddd; padding:10px 10px 40px 10px; position:relative; overflow:hidden; zoom:1;border-bottom:1px solid #ddd;}
	table.table_wrap td.tdw ul.db_lists li .con .d_title_in{position:relative; font-size:14px; font-weight:bold; height:30px; line-height:30px;}
	table.table_wrap td.tdw ul.db_lists li .con .d_title_in a{position:absolute; right:0; color:#1dd2af; font-size:12px; font-weight:normal; top:0; text-decoration:none;}
	table.table_wrap td.tdw ul.db_lists li .con .miaoshu{font-size:12px; color:#999; height:24px; line-height:24px;}
	table.table_wrap td.tdw ul.db_lists li .con .miaoshu span{padding-right:20px;}
	table.table_wrap td.tdw ul.db_lists li .con .play_box{position:relative; padding:5px 0;}
	table.table_wrap td.tdw ul.db_lists li .con .play_box img{width:100%; height:14vw;}
	table.table_wrap td.tdw ul.db_lists li .con .play_box .play_btn{width:20%; height:20%; background:url(__PUBLIC__/images/play_btn.png) top center no-repeat; background-size:contain; border:none; cursor:pointer; position:absolute; left:50%; top:50%; margin-left:-10%; margin-top:-10%; outline:0;}
	table.table_wrap td.tdw ul.db_lists li .con dl{width:100%; overflow:hidden; zoom:1; position:absolute; margin-bottom:1px; bottom:0; left:0; border-top:1px solid #ddd;}
	table.table_wrap td.tdw ul.db_lists li .con dl dd{width:46%; border-left:1px solid #ddd; float:left; text-align:center; height:36px; line-height:36px; display:inline-block; color:#1dd2af;}
	table.table_wrap td.tdw ul.db_lists li .con dl dd a{color:#999; text-decoration:none;}
	table.table_wrap td.tdw ul.db_lists li .con dl dd a:hover{color:#1dd2af;}
	
	table.table_wrap td.tds{width:25%;}
	table.table_wrap td.tds .r_box{border:1px solid #ddd; margin-bottom:20px;}
	table.table_wrap td.tds .r_box .title{background:#dde4e6; color:#2c3e50; font-size:20px; font-weight:bold; text-align:center; height:50px; line-height:50px; border-bottom:1px solid #ddd;}
	table.table_wrap td.tds .r_box .bw_con{position:relative;}
	table.table_wrap td.tds .r_box .bw_con .liuyan_list{position:relative;}
	table.table_wrap td.tds .r_box .bw_con .liuyan_list .xtxx{background:#eaeabc url(__PUBLIC__/images/xtxx.jpg) 10px center no-repeat; padding-left:35px; color:#666; height:30px; line-height:30px;}
	table.table_wrap td.tds .r_box .bw_con .liuyan_list ul{max-height:220px; overflow-y:auto;}
	table.table_wrap td.tds .r_box .bw_con .btn_box1{border-bottom:1px solid #ddd; padding:10px;}
	table.table_wrap td.tds .r_box .bw_con .btn_box2{border-top:1px solid #ddd; padding:10px;}
	table.table_wrap td.tds .r_box .bw_con .btn_box1 .input_box,table.table_wrap td.tds .r_box .bw_con .btn_box2 .input_box{border:1px solid #ddd; height:40px; position:relative;}
	table.table_wrap td.tds .r_box .bw_con .btn_box1 .input1,table.table_wrap td.tds .r_box .bw_con .btn_box2 .input1{height:40px; width:80%; outline:0; padding:0 5px; border:0;}
	table.table_wrap td.tds .r_box .bw_con .btn_box1 .btn1,table.table_wrap td.tds .r_box .bw_con .btn_box2 .btn1{ background:#2c3e50; color:#fff; text-align:center; border:0; cursor:pointer; height:40px; outline:0; padding:0 10px; position:absolute; right:0; top:0;}
	table.table_wrap td.tds .r_box .bw_con ul{padding:10px;}
	table.table_wrap td.tds .r_box .bw_con ul li{line-height:24px; color:#2c3e50; padding:2px 0;}
	table.table_wrap td.tds .r_box .bw_con ul li a{color:#2c3e50;white-space: nowrap; overflow: hidden; text-overflow: ellipsis;height:24px; line-height:24px; width:100%; text-decoration:none;}
	table.table_wrap td.tds .r_box .bw_con ul li a:hover{color:#1dd2af;}
	table.table_wrap td.tds .r_box .bw_con ul li span.l_b{color:#999;}
</style>
</head>

<body>
<div class="wrap">
    <ul class="nav nav-tabs" style="font-size:14px;font-family: 'Microsoft YaHei'">
			<if condition="$add_from eq 0">
				<li><a href="{:U('Admin/Live/index')}">直播列表</a></li>
				<li><a href="{:U('Admin/Live/add')}">添加直播</a></li>
			</if>
			<li class="active"><a>导播管理</a></li>
	</ul>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_wrap">
  <tr>
    <td align="left" valign="top" class="tdw">
      <input type="hidden" id="live_id" value="{$live_id}">
		<input type="hidden" id="is_fast" value="{$is_fast}">
   	  <div class="title">导播管理控制台 <a href="javascript:void(1);" class="add_btn" data-status="1" id="startAllBtn">全部开启信号源</a></div>
      <ul class="db_lists" id="angleListUl">
          <foreach name="angleList" item="vo" key="k">
           <if condition="$vo.status neq null">
        	<li>
            	<div class="d_title">机位{$k+1} </div>
                <div class="con">
                  <div class="d_title_in"><span id="name_span_{$k+1}">{$vo.name}</span> <a href="javascript:void(1);" class="update_name" data-id="{$vo.camera_id}" data-index="{$k+1}" id="update_name_{$k+1}">修改</a></div>
                  <p class="miaoshu"><span style="width:56px;padding-right:0;">信号来源：<if condition="$vo.signal_source eq 1">频道</if><if condition="$vo.signal_source eq 2">资源池</if></span>
                  <span style="padding-right:0;float: right; width:122px;text-overflow:ellipsis;word-break:keep-all;white-space:nowrap; overflow:hidden;" title="{$vo.source_name}"><if condition="$vo.signal_source eq 1">线路：{$vo.source_name}</if><if condition="$vo.signal_source eq 2">视频名称：{$vo.source_name}</if></span></p>
                  <div class="play_box">
                    	<input type="button" data-id="{$vo.camera_id}" data-signal_source="{$vo.signal_source}" data-file_id="{$vo.file_id}" data-txy_channel_id="{$vo.txy_channel_id}" data-index="{$k+1}" id="play_{$k+1}" class="play_btn" />
                    	<img src="{$image_url}" />
                    </div>
                    <dl>
                        <dd style="margin-left:-1px;width:55px;">
                        <input name="select_radio" id="select_{$k+1}" data-index="{$k+1}" style="margin-bottom:5px;" type="radio" value="" /> 选择</dd>
                        <dd style="width:85px;">
                        <a href="javascript:void(1);" class="change_status" data-id="{$vo.camera_id}" data-status="{$vo.status}" 
                        data-index="{$k+1}" id="change_status_{$k+1}"><if condition="$vo.status eq 2">开启信号源</if><if condition="$vo.status eq 1">关闭信号源</if></a></dd>
                        <dd style="width:85px;">
                        <a href="javascript:void(1);" class="change_signal" data-name="{$vo.name}" data-signal_source="{$vo.signal_source}" data-operator_id="{$vo.operator_id}" data-operator_name="{$vo.real_name}" data-source_id="{$vo.source_id}" data-id="{$vo.camera_id}" data-status="{$vo.status}" data-index="{$k+1}" id="change_signal_{$k+1}">切换信号源</a></dd>
                    </dl>                                                 
                </div>
            </li>
            </if>
            </foreach>


             <li <?php if(in_array(!empty($angleList[0]) && $live['category'],array(1,4)) && $live['is_fast'] == 1){ echo "style='display:none;'";}?> >
            	<div class="d_title">机位{$angleList|count } </div>
                <div class="con">
                	<div class="d_title_in"></div>
                  <p class="miaoshu"></p>
                  <div class="play_box">
                    	<a href="javascript:void(1);" id="addCameraAngle"><img src="__PUBLIC__/images/add_dbicon.png" /></a>
                    </div>
                    <dl>
                      <dd style="margin-left:-1px;"></dd><dd></dd>
                    </dl>                                                 
                </div>
            </li>
        </ul>
    </td>
    <td align="left" valign="top" class="tds">
    	<div class="r_box">
            <div class="title">
                                                  直播备忘
            </div>
            <div class="bw_con">
                <p>{$remark}</p>
            </div>
        </div>
        <div class="r_box">
            <div class="title">
                                                       互动聊天
            </div>
            <div class="bw_con">
           	    <div class="btn_box1">
                	<div class="input_box">
                		<input type="text" placeholder="系统消息" id="sys_msg_input" class="input1" /><input type="submit" id="send_sys_msg_btn" value="提交" class="btn1" data-type="add"/>
                    </div>
                </div>
                <div class="liuyan_list">
                    <div class="xtxx">系统消息：<span id="sys_msg_span" style="width:100px;text-overflow:ellipsis;word-break:keep-all;white-space:nowrap; overflow:hidden; "></span></div>
                    <ul id="receive_msg_ul" style="min-height:90px;">
                        
                    </ul>
                </div>
                
              	<div class="btn_box2">
                	<div class="input_box">
                		<input type="text" placeholder="实时评论互动" id="chat_msg_input" class="input1" style="width:170px;"/>
                		<span id="emoji_span" style="cursor:pointer;"></span>
                		<input type="submit" id="send_chat_msg_btn" value="提交" class="btn1" data-type="add"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="r_box" id="all_emoji_div" style="margin-top:-32px;z-index:999;background:#2c3e50;margin-right:40px;height:200px;overflow-y:scroll;visibility:hidden;"></div>
    </td>
  </tr>
</table>
<table width="100%" class="table table-hover table-bordered">
	<thead>
		<tr>
		 <th colspan="6" style="background: #dde4e6 none repeat;height:30px;color: #2c3e50;font-size: 20px;text-align:center;padding:0 0 10px 0;">资源池
		</th>
		</tr>
		<tr>
		 <th>序号</th>
		 <th>视频名称</th>
		 <th style="width:60px;">是否VR</th>
		 <th>视频文件</th>
		 <th>腾讯云fileId</th>
		 <th>操作</th>
		</tr>
	</thead>
	<tbody id="resource_video_body">
		<foreach name="videoList" item="vo" key="k">
		   <form id="video_form_{$vo.video_id}" action="{:U('Admin/LiveResourceVideo/save_video')}&live_id=" name="video_form_{$vo.video_id}" enctype="multipart/form-data" method="post">
			<tr id="video_tr_{$vo.video_id}" data-id="{$vo.video_id}" data-name="{$vo.video_name}" name="video_tr">
				<td>
					{$k+1}
				</td>
				<td>
				<input type="hidden" id="video_id_{$vo.video_id}" name="video_id" value="{$vo.video_id}">
				<input type="text" style="width:170px;" id="video_name_{$vo.video_id}" name="video_name" value="{$vo.video_name}"/>
				</td>
				<td>
				   <select id="category_{$vo.video_id}" name="category" style="width:60px;">
					   <option value="1" <if condition="$vo.category eq 1"> selected </if>>否</option>
			           <option value="2" <if condition="$vo.category eq 2"> selected </if>>是</option>
				   </select>
				</td>
				<td>
				<if condition="$vo.video_id eq 0"> 
					<input style="width:230px;" type="file" id="file_name_{$vo.video_id}" name="file" value="{$vo.file_name}"/>
				</if>
				<if condition="$vo.video_id neq 0"> 
				{$vo.file_name}
				</if>
				</td>
				<td><input style="width:170px;" type="text" id="input_file_id_{$vo.video_id}" name="input_file_id" value="{$vo.input_file_id}"/></td>
				<td>
				  <a href="javascript:void(1);" id="save_btn_{$vo.video_id}" onclick="save_video(0);">保存</a>
				  <if condition="$vo.video_id neq 0"> 
					  <a href="{:U('Admin/Live/view_live')}&signal_source=2&file_id={$vo.file_id}" target="_blank">播放</a>
					  <a href="javascript:void(1);" onclick="delete_video('{$vo.video_id}')">删除</a>
				  </if>
                </td>
			</tr>
			</form>
		</foreach>
	</tbody>
</table>
</div>
    <script src="__PUBLIC__/js/ajaxForm.js"></script>
    <script src="__PUBLIC__/js/common.js"></script>
    <script src="__PUBLIC__/js/artDialog/artDialog.js"></script>
    <script src="__PUBLIC__/js/layer/layer.js"></script>
    <script src="http://cdn.ronghub.com/RongIMLib-2.2.4.min.js"></script>
    <script src="http://cdn.ronghub.com/RongEmoji-2.2.4.min.js"></script>
	<script>
	// 对Date的扩展，将 Date 转化为指定格式的String
	// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符， 
	// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 
	// 例子： 
	// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 
	// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18 
	Date.prototype.Format = function (fmt) { //author: meizz 
	    var o = {
	        "M+": this.getMonth() + 1, //月份 
	        "d+": this.getDate(), //日 
	        "h+": this.getHours(), //小时 
	        "m+": this.getMinutes(), //分 
	        "s+": this.getSeconds(), //秒 
	        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
	        "S": this.getMilliseconds() //毫秒 
	    };
	    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	    for (var k in o)
	    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	    return fmt;
	};
	
	
	function get_all_status(){
		var status = 2;
		$('.change_status').each(function(){
			if(2 == $(this).attr('data-status')){
				status = 1;
				return;
			}
		});
		return status;
	}
	
	function init_start_all_btn(){
		//1  全部开启
		if(1 == get_all_status()){
			$('#startAllBtn').attr('data-status', 1);
			$('#startAllBtn').text('全部开启信号源');
		}else{
			// 1 全部关闭
			$('#startAllBtn').attr('data-status', 2);
			$('#startAllBtn').text('全部关闭信号源');
		}
	}
	
	function angle_channel_change(){
		var channel_id = $('#channel_id_select').val();
		var device_type = $('#channel_' + channel_id).attr('data-device_type');
//		if(3 == device_type){
//			$('#operator_id_select').css('display', '');
//			$('#operator_select_label').css('display', '');
//			$.get("{:U('Admin/Live/get_channel_operators')}&channel_id=" + channel_id, function(r){
//				if(r.data){
//					var html = '';
//					for(var item in r.data){
//						html += '<option value="' + r.data[item].operator_id +'">' + r.data[item].real_name +'</option>'
//					}
//					$('#operator_id_select').html(html);
//				}
//			});
//		}else{
//			$('#operator_id_select').css('display', 'none');
//			$('#operator_select_label').css('display', 'none');
//			$('#operator_id_select').html('<option value="0" selected></option>');
//		}
	}
	function operator_channel_change(){

	}

	function signal_source_change(){
		var signal_source = $('#signal_source_select').val();
		if(1 == signal_source){
			$('#channel_id_select').css('display', '');
			$('#channel_id_label').css('display', '');
			$('#operator_id_select').css('display', '');
			$('#operator_select_label').css('display', '');
//			if($('#operator_id_select option').length == 1 && $('#operator_id_select option').val() == 0){
//				$('#operator_id_select').css('display', 'none');
//				$('#operator_select_label').css('display', 'none');
//			}else{
//				$('#operator_id_select').css('display', '');
//				$('#operator_select_label').css('display', '');
//			}
			
			$('#video_id_select').css('display', 'none');
			$('#video_id_label').css('display', 'none');
		}else{
			$('#channel_id_select').css('display', 'none');
			$('#channel_id_label').css('display', 'none');
			$('#operator_id_select').css('display', 'none');
			$('#operator_select_label').css('display', 'none');
			$('#video_id_select').css('display', '');
			$('#video_id_label').css('display', '');
		}
	}
	
	function init_rcloud(){
		// 初始化。
		RongIMClient.init("{$ryAppKey}");
		RongIMLib.RongIMEmoji.init();
		
		var emojis = RongIMLib.RongIMEmoji.emojis;
		$('#all_emoji_div').html(emojis);
		var obj = $('#emoji_span');
		obj.html(emojis[0]);
		
		obj.click(function(){
			$('#all_emoji_div').css('visibility', 'visible');
		});
		$('#chat_msg_input').click(function(){
			$('#all_emoji_div').css('visibility', 'hidden');
		});
		
		$('#all_emoji_div span').css('cursor', 'pointer');
		$('#all_emoji_div span span').click(function(){
			var text = $(this).attr('name');
			var input = $('#chat_msg_input');
			input.val(input.val() + text);
		});
		var token = "{$rcloud_token}";
		
		// 连接融云服务器。
	    RongIMClient.connect(token, {
	        onSuccess: function(userId) {
	          console.log("Login successfully." + userId);
	        },
	        onTokenIncorrect: function() {
	          console.log('token无效');
	        },
	        onError:function(errorCode){
	              var info = '';
	              switch (errorCode) {
	                case RongIMLib.ErrorCode.TIMEOUT:
	                  info = '超时';
	                  break;
	                case RongIMLib.ErrorCode.UNKNOWN_ERROR:
	                  info = '未知错误';
	                  break;
	                case RongIMLib.ErrorCode.UNACCEPTABLE_PaROTOCOL_VERSION:
	                  info = '不可接受的协议版本';
	                  break;
	                case RongIMLib.ErrorCode.IDENTIFIER_REJECTED:
	                  info = 'appkey不正确';
	                  break;
	                case RongIMLib.ErrorCode.SERVER_UNAVAILABLE:
	                  info = '服务器不可用';
	                  break;
	              }
	              console.log(errorCode);
	            }
	      });
		  
	      // 设置连接监听状态 （ status 标识当前连接状态）
	      // 连接状态监听器
	      RongIMClient.setConnectionStatusListener({
	         onChanged: function (status) {
	             switch (status) {
	                 //链接成功
	                 case RongIMLib.ConnectionStatus.CONNECTED:
	                     console.log('链接成功');
	                     break;
	                 //正在链接
	                 case RongIMLib.ConnectionStatus.CONNECTING:
	                     console.log('正在链接');
	                     break;
	                 //重新链接
	                 case RongIMLib.ConnectionStatus.DISCONNECTED:
	                     console.log('断开连接');
	                     break;
	                 //其他设备登陆
	                 case RongIMLib.ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT:
	                     console.log('其他设备登陆');
	                     break;
	                   //网络不可用
	                 case RongIMLib.ConnectionStatus.NETWORK_UNAVAILABLE:
	                   console.log('网络不可用');
	                   break;
	                 }
	         }});
	}
	
	function receive_msg(){
		// 消息监听器
	      RongIMClient.setOnReceiveMessageListener({
	         // 接收到的消息
	         onReceived: function (message) {
	             // 判断消息类型
	             switch(message.messageType){
	                 case RongIMClient.MessageType.TextMessage:
	                        console.log(message.content.content);
	                        process_receive_msg(message);
	                     //发送的消息内容将会被打印
	                     break;
	                 case RongIMClient.MessageType.ImageMessage:
	                     // do something...
	                     break;
	                 case RongIMClient.MessageType.DiscussionNotificationMessage:
	                     // do something...
	                     break;
	                 case RongIMClient.MessageType.LocationMessage:
	                     // do something...
	                     break;
	                 case RongIMClient.MessageType.RichContentMessage:
	                     // do something...
	                     break;
	                 case RongIMClient.MessageType.DiscussionNotificationMessage:
	                     // do something...
	                     break;
	                 case RongIMClient.MessageType.InformationNotificationMessage:
	                     // do something...
	                     break;
	                 case RongIMClient.MessageType.ContactNotificationMessage:
	                     // do something...
	                     break;
	                 case RongIMClient.MessageType.ProfileNotificationMessage:
	                     // do something...
	                     break;
	                 case RongIMClient.MessageType.CommandNotificationMessage:
	                     // do something...
	                     break;
	                 case RongIMClient.MessageType.CommandMessage:
	                     // do something...
	                     break;
	                 case RongIMClient.MessageType.UnknownMessage:
	                     // do something...
	                     break;
	                 default:
	                     // 自定义消息
	                     // do something...
	             }
	         }
	     });
	}
	
	function process_receive_msg(msg){
		var text = msg.content.content;
		try{
			//解析msg
			var msg_json = JSON.parse(text);
			if(2 == msg_json.type){
				text = msg_json.msg;
			}else if(null != msg_json.type){
				return;
			}
		}catch(e){}
		text = RongIMLib.RongIMEmoji.emojiToHTML(text);
		var obj = $('#receive_msg_ul');
		obj.append('<li><span class="l_b">'+new Date().Format("hh:mm")+' '+ msg.content.user.name + '：</span>' + text + '</li>');
		obj.scrollTop(obj[0].scrollHeight);
	}
	var user = {name:"管理员",userId: 'ad_{$admin_id}'};
	//type 1 系统消息 2 聊天消息 3 机位变更消息
	function send_msg(content, type){
	   // 定义消息类型,文字消息使用 RongIMLib.TextMessage
  	   var msg = new RongIMLib.TextMessage({content: '{"type":'+ type + ',"msg":"' + content + '"}', extra: type + '', user: user});
  	   //或者使用RongIMLib.TextMessage.obtain 方法.具体使用请参见文档
  	   //var msg = RongIMLib.TextMessage.obtain("hello");
  	   var conversationtype = RongIMLib.ConversationType.CHATROOM; // 私聊
  	   var targetId = "room_{$live_id}"; // 目标 Id
  	   RongIMClient.getInstance().sendMessage(conversationtype, targetId, msg, {
  	                 // 发送消息成功
  	                 onSuccess: function (message) {
  	                     //message 为发送的消息对象并且包含服务器返回的消息唯一Id和发送消息时间戳
  	                     console.log("Send successfully");
  	                 },
  	                 onError: function (errorCode,message) {
  	                     var info = '';
  	                     switch (errorCode) {
  	                         case RongIMLib.ErrorCode.TIMEOUT:
  	                             info = '超时';
  	                             break;
  	                         case RongIMLib.ErrorCode.UNKNOWN_ERROR:
  	                             info = '未知错误';
  	                             break;
  	                         case RongIMLib.ErrorCode.REJECTED_BY_BLACKLIST:
  	                             info = '在黑名单中，无法向对方发送消息';
  	                             break;
  	                         case RongIMLib.ErrorCode.NOT_IN_DISCUSSION:
  	                             info = '不在讨论组中';
  	                             break;
  	                         case RongIMLib.ErrorCode.NOT_IN_GROUP:
  	                             info = '不在群组中';
  	                             break;
  	                         case RongIMLib.ErrorCode.NOT_IN_CHATROOM:
  	                             info = '不在聊天室中';
  	                             break;
  	                         default :
  	                             info = x;
  	                             break;
  	                     }
  	                     console.log('发送失败:' + info);
  	                 }
  	             }
  	         );
	}
	
	function load_angle_list(){
		$('#angleListUl').load('{:U("Admin/Live/angle_list")}&live_id='+$('#live_id').val()+'&is_fast='+$('#is_fast').val());
	}
	
	function add_click(){
		$(".update_name").click(function(){
			var index = $(this).attr('data-index');
			var camera_id = $(this).attr('data-id');
			layer.prompt({
				   title: '修改机位名称',
				   value:$('#name_span_'+index).text(),
				   formType: 0 //prompt风格，支持0-2
				 }, function(name){
					 if(null == name || '' == name){
						 layer.msg('机位名称不能为空！');
						 return;
					 }
					 $.post('{:U("Admin/Live/edit_angle_name")}', {camera_id:camera_id, name:name}, function(result){
						 if(result.status == '1'){
							$('#name_span_'+index).text(name)
						 	layer.msg('修改成功！');
						 }
				     });
				 });
		});
		$(".change_status").click(function(){
			var index = $(this).attr('data-index');
			var camera_id = $(this).attr('data-id');
			var status = $(this).attr('data-status');
			if($('#select_'+index).attr("checked")){
				layer.confirm('您确定要' + $(this).text() + '吗？', {icon: 3, title:'提示'}, function(index){
					$.post('{:U("Admin/Live/edit_angle_status")}', {camera_id:camera_id, status:status}, function(result){
						 if(result.status == '1'){
						 	layer.msg('操作成功！');
						 	if(1 == status){
						 		$('#change_status_'+index).attr('data-status', 2)
							 	$('#change_status_'+index).text('开启信号源');
						 	}else{
						 		$('#change_status_'+index).attr('data-status', 1)
							 	$('#change_status_'+index).text('关闭信号源');
						 	}
						 	send_msg($('#live_id').val(), 3);
						 	init_start_all_btn();
						 }
				     });
					 layer.close(index);
				});
			}else{
				layer.msg('请先选择！');
			}
		});
		
		$(".change_signal").click(function(){
			var index = $(this).attr('data-index');
			var camera_id = $(this).attr('data-id');
			var name = $(this).attr('data-name');
			var signal_source = $(this).attr('data-signal_source');
			var operator_id = $(this).attr('data-operator_id');
			var real_name = $(this).attr('data-operator_name');
			var source_id = $(this).attr('data-source_id');
			var contentHtml = '<div style="width:318px;"><div style="width:92px;float:left;height:32px;font-size:14px;text-align:right;padding-top:6px;">机位名称：</div><div style="width:220px;float:right;"><input type="text" id="angle_name_input" value="'+$('#name_span_'+index).text()+'"></div> '
	              + '<div style="width:92px;float:left;height:32px;font-size:14px;text-align:right;padding-top:12px;">信号来源：</div><div style="width:220px;float:right;">'
                + '<select id="signal_source_select" onchange="signal_source_change();">';
            if(1 == signal_source){
            	contentHtml += '<option value="1" selected>频道</option><option value="2">资源池</option>';
            }else{
            	contentHtml += '<option value="1">频道</option><option value="2" selected>资源池</option>';
            }
            contentHtml += '</select></div><div id="channel_id_label" style="width:92px;float:left;height:32px;font-size:14px;text-align:right;padding-top:8px;';
            if(2 == signal_source){
            	contentHtml += 'display:none;';
            }
            contentHtml += '">推流线路：</div><div style="width:220px;float:right;"> <select id="channel_id_select"';
            if(2 == signal_source){
				contentHtml += ' style="display:none;" ';
			}
            contentHtml += ' onchange="angle_channel_change();">';
			for(var o in channelList){
				contentHtml += '<option id="channel_' + channelList[o].channel_id + '" data-device_type="'+channelList[o].device_type+'" value="'+channelList[o].channel_id+'"';
				if(1 == signal_source && channelList[o].channel_id == source_id){
					contentHtml += ' selected ';
				}
				
				contentHtml += '>' + channelList[o].channel_name + '</option>';
			}
			contentHtml += '</select></div><div id="video_id_label" style="width:92px;float:left;height:32px;font-size:14px;text-align:right;padding-top:6px;';
			if(1 == signal_source){
            	contentHtml += ' display:none;';
            }
			
			contentHtml += '">选择资源：</div><div style="width:220px;float:right;"> <select id="video_id_select" ';
			if(1 == signal_source){
            	contentHtml += ' style="display:none;"';
            }
			
			contentHtml += ' >';
			var videoList = get_video_list();
			for(var o in videoList){
				contentHtml += '<option value="'+videoList[o].video_id +'"';
				if(2 == signal_source && videoList[o].video_id == source_id){
					contentHtml += ' selected ';
				}
				contentHtml += '>'+ videoList[o].video_name + '</option>';
			}
			contentHtml += '</select></div><div id="operator_select_label" style="width:92px;float:left;height:32px;font-size:14px;text-align:right;padding-top:6px;">推流业务员：</div><div style="width:220px;float:right;"><select id="operator_id_select"';
			if(2 == signal_source){
				contentHtml += ' style="display:none;" ';
			}
			contentHtml += ' onchange="operator_channel_change();">';

//			contentHtml += '<option id="admin_' + operator_id + '" value="'+operator_id+'"';
//			contentHtml += ' selected >'+ real_name + '</option>';

			for(var o in operatorList){
				contentHtml += '<option id="admin_' + operatorList[o].admin_id + '" value="'+operatorList[o].admin_id+'"';
				if(1 == signal_source && operatorList[o].admin_id == operator_id){
					contentHtml += ' selected ';
				}
				contentHtml += '>' + operatorList[o].real_name + '</option>';
			}

			contentHtml += '></select></div>';
			
			art.dialog({
			  title: "切换信号源",
			  icon: '',
			  content: contentHtml,
			  close: function () {
			      return true;
			  },
			  okVal:"确定",
			  ok: function () {
			  	var angle_name = $('#angle_name_input').val();
			  	if(null == angle_name || '' == angle_name){
			  		layer.msg('请输入机位名称！');
			  		return false;
			  	}
			  	var signal_source = $('#signal_source_select').val();
			  	var source_id;
			  	if(1 == signal_source){
			  		source_id = $('#channel_id_select').val();
			  	}else{
			  		source_id = $('#video_id_select').val();
			  	}
			  	
			  	var operator_id = $('#operator_id_select').val();
			  	$.post('{:U("Admin/Live/update_camera_angle")}', {live_id:$('#live_id').val(),camera_id:camera_id,name:angle_name, signal_source:signal_source,source_id:source_id, operator_id:operator_id}, function(result){
						 if(result.status == '1'){
						 	layer.msg('操作成功！');
						 	send_msg($('#live_id').val(), 3);
						 	load_angle_list();
							location.reload();
						 }else{
							 layer.msg(result);
							 send_msg($('#live_id').val(), 8);
						 }
				     });
			  },
			  cancelVal: '关闭',
			  cancel: true
			});
			angle_channel_change();
		});
		init_start_all_btn();
		
		$(".play_btn").click(function(){
			var index = $(this).attr('data-index');
			var camera_id = $(this).attr('data-id');
			if($('#select_'+index).attr("checked")){
				window.open('{:U("Admin/Live/view_live")}&channel_id='+$(this).attr('data-txy_channel_id')+'&file_id='+$(this).attr('data-file_id')+'&signal_source='+$(this).attr('data-signal_source'));
			}else{
				layer.msg('请先选择！');
			}
		});
		
		$("#addCameraAngle").click(function(){
			var contentHtml = '<div style="width:318px;"><div style="width:92px;float:left;height:32px;font-size:14px;text-align:right;padding-top:6px;">机位名称：</div><div style="width:220px;float:right;"><input type="text" id="angle_name_input"></div> '
				              + '<div style="width:92px;float:left;height:32px;font-size:14px;text-align:right;padding-top:12px;">信号来源：</div><div style="width:220px;float:right;">'
                              + '<select id="signal_source_select" onchange="signal_source_change();"><option value="1">频道</option><option value="2">资源池</option></select></div>'
			                  + '<div id="channel_id_label" style="width:92px;float:left;height:32px;font-size:14px;text-align:right;padding-top:8px;">推流线路：</div><div style="width:220px;float:right;">'
			                  + '<select id="channel_id_select" onchange="angle_channel_change();">';
			for(var o in channelList){
				contentHtml += '<option id="channel_' + channelList[o].channel_id + '" data-device_type="'+channelList[o].device_type+'" value="'+channelList[o].channel_id+'">' + channelList[o].channel_name + '</option>';
			}
			contentHtml += '</select></div><div id="video_id_label" style="width:92px;float:left;height:32px;font-size:14px;text-align:right;padding-top:6px;display:none;">选择资源：</div><div style="width:220px;float:right;">'
                           + '<select id="video_id_select" style="display:none;">';
            var videoList = get_video_list();
			for(var o in videoList){
				contentHtml += '<option value="'+videoList[o].video_id+'">' + videoList[o].video_name + '</option>';
			}
			contentHtml += '</select></div><div id="operator_select_label" style="width:92px;float:left;height:32px;font-size:14px;text-align:right;padding-top:6px;">推流业务员：</div><div style="width:220px;float:right;"><select id="operator_id_select" onchange="operator_channel_change();">';
			for(var o in operatorList){
				contentHtml += '<option id="operator_' + operatorList[o].admin_id + ' " value="'+operatorList[o].admin_id+'">' + operatorList[o].real_name + '</option>';
			}
			contentHtml += '</select></div>';
			
			art.dialog({
                title: "添加机位",
                icon: '',
                content: contentHtml,
                close: function () {
                    return true;
                },
                okVal:"确定",
                ok: function () {
                	var angle_name = $('#angle_name_input').val();
                	if(null == angle_name || '' == angle_name){
                		layer.msg('请输入机位名称！');
                		return false;
                	}
                	var signal_source = $('#signal_source_select').val();
                	var source_id;
                	if(1 == signal_source){
                		source_id = $('#channel_id_select').val();
                	}else{
                		source_id = $('#video_id_select').val();
                	}
                	
                	var operator_id = $('#operator_id_select').val();
                	$.post('{:U("Admin/Live/add_camera_angle")}', {live_id:$('#live_id').val(),name:angle_name, signal_source:signal_source,source_id:source_id, operator_id:operator_id}, function(result){
						 if(result.status == '1'){
						 	layer.msg('操作成功！');
						 	send_msg($('#live_id').val(), 3);
						 	load_angle_list();
						 }else{
							 layer.msg(result);
							 send_msg($('#live_id').val(), 8);
						 }
				     });
                },
                cancelVal: '关闭',
                cancel: true
            });
			angle_channel_change();
		});
		
	}
	
	function get_video_list(){
		var videoList = [];
		$('tr[name="video_tr"]').each(function(){
			var id = $(this).attr('data-id');
			var o = {};
			if('0' != id){
				o.video_id = id;
				o.video_name = $(this).attr('data-name');
				videoList.push(o);
			}
		});
		
		return videoList;
	}
	
	function save_video(video_id){
		var video_name = $('#video_name_'+video_id).val();
		if(null == video_name || '' == video_name){
			layer.msg('视频名称不能为空！');
			return;
		}
		
		var file_name = $('#file_name_'+video_id).val();
		var input_file_id = $('#input_file_id_'+video_id).val();
		if((null == file_name || '' == file_name) && (null == input_file_id || '' == input_file_id)){
			layer.msg('视频文件或者腾讯云fileId不能同时为空！');
			return;
		}
		var live_id = $('#live_id').val();
		var form = $('#video_form_'+video_id);
		form.attr('action', $('#video_form_'+video_id).attr('action') + live_id);
		var btn = $('#save_btn_'+video_id);
		//ie处理placeholder提交问题
        if ($.browser.msie) {
            form.find('[placeholder]').each(function () {
                var input = $(this);
                if (input.val() == input.attr('placeholder')) {
                    input.val('');
                }
            });
        }
        
        form.ajaxSubmit({
            url: form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
            dataType: 'json',
            beforeSubmit: function (arr, $form, options) {
            	btn.data("loading",true);
                var text = btn.text();
                //按钮文案、状态修改
                btn.text(text + '中...').prop('disabled', true).addClass('disabled');
            },
            success: function (data, statusText, xhr, $form) {
                var text = btn.text();
                //按钮文案、状态修改
                btn.removeClass('disabled').text(text.replace('中...', ''));
                if (data.state === 'success') {
                	layer.msg('保存成功！');
                	
            		setTimeout(function(){
            			location=location;
            		}, 1000);
                	
                	//$('#resource_video_body').load('{:U("Admin/LiveResourceVideo/video_list")}&live_id=' + live_id);
                } else if (data.state === 'fail') {
                	layer.msg(data.info);
                    btn.removeProp('disabled').removeClass('disabled');
                }
            },
            complete: function(){
            	btn.data("loading", false);
            }
        });
		
	}
	
	function delete_video(video_id){
		layer.confirm('您确定要删除吗？', {icon: 3, title:'提示'}, function(index){
			$.post('{:U("Admin/LiveResourceVideo/delete_video")}', {video_id:video_id}, function(result){
				 if(result.status == '1'){
				 	layer.msg('操作成功！');
				 	$('#resource_video_body').load('{:U("Admin/LiveResourceVideo/video_list")}&live_id=' + $('#live_id').val());
				 }
		     });
			layer.close(index);
		});
	}
	
	var channelList = {$channelList};
	var operatorList = {$operatorList};

	$(document).ready(function(){

		init_rcloud();
		
		$("#startAllBtn").click(function(){
			var status = $(this).attr('data-status');
			layer.confirm('您确定要' + $(this).text() + '吗？', {icon: 3, title:'提示'}, function(index){
				$.post('{:U("Admin/Live/change_all_status")}', {live_id:$('#live_id').val(), status:status}, function(result){
					 if(result.status == '1'){
					 	layer.msg('操作成功！');
					 	send_msg($('#live_id').val(), 3);
					 	load_angle_list();
					 }
			     });
				  layer.close(index);
			});
        });
		add_click();
		
		receive_msg();
	  
        $("#send_sys_msg_btn").click(function(){
        	var msg = $.trim($("#sys_msg_input").val());
        	if('' == msg){
        		layer.msg('请输入消息内容！');
        		return;
        	}
			$.ajax({
				type:"post",
				async:false,
				url:"{:U('Admin/Movement/filter_words')}",
				data:'content='+msg,
				dataType:"text",
				success:function(data){
					if(data){
						if(confirm('您编辑的内容涉及敏感词'+data+'是否继续操作')){
							flag = true;
							return true;
						}else{
							flag = false;
							return false;
						}
					}else{
						flag = true;
						return true;
					}
				}
			});
			if(flag == false){
				return flag;
			}
    	    send_msg(msg, 1);
    	    $('#sys_msg_span').text(msg);
    	    $('#sys_msg_span').attr('title', msg);
    	    $("#sys_msg_input").val('');
        });
        $("#send_chat_msg_btn").click(function(){
        	var msg = $.trim($("#chat_msg_input").val());
        	if('' == msg){
        		layer.msg('请输入消息内容！');
        		return;
        	}
			var flag = false;
			$.ajax({
				type:"post",
				async:false,
				url:"{:U('Admin/Movement/filter_words')}",
				data:'content='+msg,
				dataType:"text",
				success:function(data){
					if(data){
						if(confirm('您编辑的内容涉及敏感词'+data+'是否继续操作')){
							flag = true;
							return true;
						}else{
							flag = false;
							return false;
						}
					}else{
						flag = true;
						return true;
					}
				}
			});
			if(flag == false){
				return flag;
			}
        	var str = RongIMLib.RongIMEmoji.symbolToEmoji(msg);
    	    send_msg(str, 2);
    	    msg = RongIMLib.RongIMEmoji.symbolToHTML(msg);
    	    var obj = $('#receive_msg_ul');
			obj.append('<li><span class="l_b">'+new Date().Format("hh:mm")+' 我：</span>' + msg + '</li>');
			obj.scrollTop(obj[0].scrollHeight);
    	    $("#chat_msg_input").val('');
    	    $('#all_emoji_div').css('visibility', 'hidden');
        });
	});
	</script>
</body>
</html>
